package com.sinodata.bsm.center.service.resource;

import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sinodata.bsm.center.cache.ResCache;
import com.sinodata.bsm.center.cache.ResTypeCache;
import com.sinodata.bsm.center.dao.BaseDao;
import com.sinodata.bsm.common.vo.*;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-5-7 下午4:06:29          liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
@Service
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class ResTypeService {
    @Autowired
    private ResTypeCache resTypeCache;
    @Autowired
    private BaseDao baseDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public ResType get(Long id) {
        return resTypeCache.get(id);
    }

    public List<ResType> getAll() {
        return resTypeCache.getAll();
    }

    public List<ResType> getRoots() {
        return resTypeCache.getRootResType();
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void saveMonitorTypeRel(MotiRestypeRel rel) {
        List<MotiRestypeRel> list = (List<MotiRestypeRel>) baseDao.findListByHql("from MotiRestypeRel where resTypeId=" + rel.getResTypeId());
        if (list != null) {
            for (int i = list.size() - 1; i >= 0; i--) {
                baseDao.delete(list.get(i));
            }
        }
        if (rel.getMoitTypeId() != 0) {
            baseDao.save(rel);
        }
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteMonitorTypeRel(MotiRestypeRel rel) {
        //  jdbcTemplate.
    }
}
